﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Telerik.Web.UI;
using Asah.SiteWorx.SiteMap;

/// <summary>
/// Summary description for Utility
/// </summary>
public abstract class Utility
{
    public static bool PageInPreviewMode()
    {
        if (HttpContext.Current.Request.QueryString["preview"] != null)
            if (HttpContext.Current.Request.QueryString["preview"].ToString() == "true")
                return true;
            else
                return false;
        return false;
    }

    public static List<EditorLink> LoadCustomLinks()
    {
        List<EditorLink> links = new List<EditorLink>();

        EditorLink radLink;
        LinkedList<PageInfo> menu = NavigationMenu.GetFullMenu();
        foreach (PageInfo info in menu)
        {
            radLink = new EditorLink();
            radLink.Name = info.MenuText;
            radLink.Href = info.Url.Replace("~/", "");
            LoadSubCustomLinks(info.ChildPages, ref radLink);
            links.Add(radLink);
        }

        List<PageInfo> nonMenuPageList = NavigationMenu.GetFullNonMenu();
        foreach (PageInfo info in nonMenuPageList)
        {
            radLink = new EditorLink();
            radLink.Name = info.MenuText;
            radLink.Href = info.Url.Replace("~/", "");
            links.Add(radLink);
        }
        return links;
    }

    private static void LoadSubCustomLinks(LinkedList<PageInfo> childMenu, ref EditorLink radLink)
    {
        foreach (PageInfo info in childMenu)
        {
            EditorLink radChildLink = new EditorLink();
            radChildLink.Name = info.MenuText;
            radChildLink.Href = info.Url.Replace("~/", "");
            LoadSubCustomLinks(info.ChildPages, ref radChildLink);
            radLink.ChildLinks.Add(radChildLink);
        }
    }
}
